package com.jack.payment.controller.admin.auth;


import com.jack.payment.annotation.PagingLimit;
import com.jack.payment.entity.common.BusinessException;
import com.jack.payment.entity.common.CommonAskParam;
import com.jack.payment.entity.common.CommonResult;
import com.jack.payment.entity.filter.PayFilter;
import com.jack.payment.entity.generate.billing.BillingModel;
import com.jack.payment.entity.generate.user.UserModel;
import com.jack.payment.entity.result.PageVo;
import com.jack.payment.service.basic.BillingServiceImpl;
import com.jack.payment.util.common.PageResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Tag(name = "流水信息")
@RequestMapping("/api/v1/billing")
public class BillingController {
    private Logger log = LoggerFactory.getLogger(BillingController.class);

    @Autowired
    private BillingServiceImpl billingService;
    @Autowired
    private PageResultUtil pageResultUtil;


    @Operation(summary = "流水数据")
    @RequestMapping(value = "billing", method = {RequestMethod.POST})
    @ResponseBody
    @PagingLimit
    public CommonResult billing(@RequestBody CommonAskParam<PayFilter.BillingFilter> data) throws BusinessException {
        UserModel getUserModel = (UserModel) data.getCommon().getUserId();
        PayFilter.BillingFilter requestParam = data.getData();
        requestParam.setUserId(getUserModel.getId());

        Integer resultCount = billingService.filterBillingCount(requestParam);
        // 判断数据是否超出
        pageResultUtil.judgeRequestCount(
                requestParam.getPage(),
                resultCount
        );
        List<BillingModel> pageList = billingService.filterBillingList(requestParam);
        return CommonResult.ok(new PageVo<BillingModel>(
                pageList,
                pageResultUtil.resultPageComputer(requestParam.getCount(), resultCount),
                requestParam.getPage() / requestParam.getCount()));
    }

}
